<template>
  <div>
    <!-- <p>{{ urlParams }}</p> -->
    <h1>1111111111111111111111111111</h1>
    <h1>2222222222222222222</h1>
  </div>
</template>

<script>
import { getDynamicData } from "@/APIs/flowSegmentation";
import { getQuery } from "@/assets/js/utils";

export default {
  data() {
    return {};
  },
  metaInfo() {
    return {
      title: "",
    };
  },
  computed: {
    urlParams() {
      const channel = getQuery(this, "channel");
      const reffer = getQuery(this, "reffer");
      const sid = getQuery(this, "sid");
      const bid = getQuery(this, "bid");
      return `channel=${channel}&reffer=${reffer}&sid=${sid}&bid=${bid}`;
    },
  },
  methods: {
    getRandomNum(end) {
      let num = Math.floor(Math.random() * end);
      return num;
    },
    //   获取多渠道数据
    async getPageUrl() {
      const { data } = await getDynamicData("flow_segmentation");
      if (data.appoint == "{}") {
        // 随机
        const arr = JSON.parse(data.reflection);
        return arr[this.getRandomNum(arr.length)];
      } else {
        // 指定
        return JSON.parse(data.appoint);
      }
    },
  },
  async created() {
    console.log("11111111111111111111111111111");
    //   获取多渠道数据
    const res = await this.getPageUrl();
    const url = `${res.page}${this.urlParams}`;
    console.log(url);
    // window.location.href = url;
  },
};
</script>

<style lang="less"></style>
